/*
 * Filename:    StandardscoreController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月31日
 */
package com.paic.mhis.hcpms.agreement.healthcareprovider.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.agreement.healthcareprovider.biz.service.StandardscoreService;
import com.paic.mhis.hcpms.agreement.healthcareprovider.dto.StandardScoreDTO;
import com.paic.mhis.hcpms.agreement.healthcareprovider.util.HttpProcessUtil;
import com.paic.mhis.hcpms.agreement.healthcareprovider.util.SortTools;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.paic.pafa.web.BaseRest;

/**
 * 
 * @author EX-FENGHE001
 * 
 */
@Controller
public class StandardscoreController extends BaseRest {

	@BizServicesProxy
	private StandardscoreService standardscoreService;

	@RequestMapping(value = "/hcp/hcp/standardscore/save.do", method = RequestMethod.POST)
	public Map<String, Object> save(HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute(
					"user");
			String str = HttpProcessUtil.readRequestBody(request);
			JSONArray jarray = JSON.parseArray(str);
			String loginName = user.getUsername();
			result = standardscoreService.saveStandardScore(jarray, loginName);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

	@RequestMapping(value = "/hcp/hcp/standardscore/query.do", method = RequestMethod.GET)
	public Map<String, Object> findStandardScore(HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			String scoreType = request.getParameter("scoreType");
			StandardScoreDTO dto = new StandardScoreDTO();
			dto.setScoreType(scoreType);
			dto = standardscoreService.findStandardScore(dto);

			SortTools.sortListToNomalOrder(dto);// 对评分标准排序

			result = new HashMap<String, Object>();
			result.put("result", dto);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

	@RequestMapping(value = "/hcp/hcp/standardscore/queryDetail.do", method = RequestMethod.GET)
	public Map<String, Object> findStandardScoreDetail(
			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			String id = request.getParameter("standardscoreid");
			StandardScoreDTO dto = new StandardScoreDTO();
			dto = standardscoreService.findStandardScoreDetail(id);
			result = new HashMap<String, Object>();
			result.put("result", dto);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

	@RequestMapping(value = "/hcp/hcp/standardscore/queryTotalValue.do", method = RequestMethod.GET)
	public Map<String, Object> queryTotalValue(HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			String id = request.getParameter("standardscoreid");
			String type = request.getParameter("type");
			StandardScoreDTO dto = new StandardScoreDTO();
			Map queryMap = new HashMap<String, String>();
			queryMap.put("id", id);
			queryMap.put("type", type);
			dto = standardscoreService.queryTotalValue(queryMap);
			result = new HashMap<String, Object>();
			result.put("result", dto);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

	@RequestMapping(value = "/hcp/hcp/standardscore/deleteBySuperId.do", method = RequestMethod.GET)
	public Map<String, Object> deleteStandardScoreBySuperId(
			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			UserDetails user = (UserDetails) request.getSession().getAttribute(
					"user");
			String id = request.getParameter("standardscoreid");
			result = standardscoreService.deleteStandardScoreBySuperId(id,
					user.getUsername());
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}
}
